package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.PmsProductOperateLog;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.PmsProductOperateLogDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface PmsProductOperateLogMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, productId, priceOld, priceNew, salePriceOld, salePriceNew, giftPointOld, giftPointNew, usePointLimitOld, usePointLimitNew, operateMan, createTime);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(PmsProductOperateLog record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productId).equalTo(record::getProductId)
                  .set(priceOld).equalTo(record::getPriceOld)
                  .set(priceNew).equalTo(record::getPriceNew)
                  .set(salePriceOld).equalTo(record::getSalePriceOld)
                  .set(salePriceNew).equalTo(record::getSalePriceNew)
                  .set(giftPointOld).equalTo(record::getGiftPointOld)
                  .set(giftPointNew).equalTo(record::getGiftPointNew)
                  .set(usePointLimitOld).equalTo(record::getUsePointLimitOld)
                  .set(usePointLimitNew).equalTo(record::getUsePointLimitNew)
                  .set(operateMan).equalTo(record::getOperateMan)
                  .set(createTime).equalTo(record::getCreateTime);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(PmsProductOperateLog record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productId).equalToWhenPresent(record::getProductId)
                  .set(priceOld).equalToWhenPresent(record::getPriceOld)
                  .set(priceNew).equalToWhenPresent(record::getPriceNew)
                  .set(salePriceOld).equalToWhenPresent(record::getSalePriceOld)
                  .set(salePriceNew).equalToWhenPresent(record::getSalePriceNew)
                  .set(giftPointOld).equalToWhenPresent(record::getGiftPointOld)
                  .set(giftPointNew).equalToWhenPresent(record::getGiftPointNew)
                  .set(usePointLimitOld).equalToWhenPresent(record::getUsePointLimitOld)
                  .set(usePointLimitNew).equalToWhenPresent(record::getUsePointLimitNew)
                  .set(operateMan).equalToWhenPresent(record::getOperateMan)
                  .set(createTime).equalToWhenPresent(record::getCreateTime);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<PmsProductOperateLog> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("PmsProductOperateLogResult")
    Optional<PmsProductOperateLog> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "PmsProductOperateLogResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "product_id", property = "productId", jdbcType = JdbcType.BIGINT),
            @Result(column = "price_old", property = "priceOld", jdbcType = JdbcType.DECIMAL),
            @Result(column = "price_new", property = "priceNew", jdbcType = JdbcType.DECIMAL),
            @Result(column = "sale_price_old", property = "salePriceOld", jdbcType = JdbcType.DECIMAL),
            @Result(column = "sale_price_new", property = "salePriceNew", jdbcType = JdbcType.DECIMAL),
            @Result(column = "gift_point_old", property = "giftPointOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "gift_point_new", property = "giftPointNew", jdbcType = JdbcType.INTEGER),
            @Result(column = "use_point_limit_old", property = "usePointLimitOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "use_point_limit_new", property = "usePointLimitNew", jdbcType = JdbcType.INTEGER),
            @Result(column = "operate_man", property = "operateMan", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<PmsProductOperateLog> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, pmsProductOperateLog, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, pmsProductOperateLog, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(PmsProductOperateLog record) {
        return MyBatis3Utils.insert(this::insert, record, pmsProductOperateLog, c ->
                c.map(productId).toProperty("productId")
                 .map(priceOld).toProperty("priceOld")
                 .map(priceNew).toProperty("priceNew")
                 .map(salePriceOld).toProperty("salePriceOld")
                 .map(salePriceNew).toProperty("salePriceNew")
                 .map(giftPointOld).toProperty("giftPointOld")
                 .map(giftPointNew).toProperty("giftPointNew")
                 .map(usePointLimitOld).toProperty("usePointLimitOld")
                 .map(usePointLimitNew).toProperty("usePointLimitNew")
                 .map(operateMan).toProperty("operateMan")
                 .map(createTime).toProperty("createTime")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(PmsProductOperateLog record) {
        return MyBatis3Utils.insert(this::insert, record, pmsProductOperateLog, c ->
                c.map(productId).toPropertyWhenPresent("productId", record::getProductId)
                 .map(priceOld).toPropertyWhenPresent("priceOld", record::getPriceOld)
                 .map(priceNew).toPropertyWhenPresent("priceNew", record::getPriceNew)
                 .map(salePriceOld).toPropertyWhenPresent("salePriceOld", record::getSalePriceOld)
                 .map(salePriceNew).toPropertyWhenPresent("salePriceNew", record::getSalePriceNew)
                 .map(giftPointOld).toPropertyWhenPresent("giftPointOld", record::getGiftPointOld)
                 .map(giftPointNew).toPropertyWhenPresent("giftPointNew", record::getGiftPointNew)
                 .map(usePointLimitOld).toPropertyWhenPresent("usePointLimitOld", record::getUsePointLimitOld)
                 .map(usePointLimitNew).toPropertyWhenPresent("usePointLimitNew", record::getUsePointLimitNew)
                 .map(operateMan).toPropertyWhenPresent("operateMan", record::getOperateMan)
                 .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsProductOperateLog> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, pmsProductOperateLog, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsProductOperateLog> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, pmsProductOperateLog, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsProductOperateLog> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, pmsProductOperateLog, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsProductOperateLog> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, pmsProductOperateLog, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(PmsProductOperateLog record) {
        return update(c ->
                c.set(productId).equalTo(record::getProductId)
                 .set(priceOld).equalTo(record::getPriceOld)
                 .set(priceNew).equalTo(record::getPriceNew)
                 .set(salePriceOld).equalTo(record::getSalePriceOld)
                 .set(salePriceNew).equalTo(record::getSalePriceNew)
                 .set(giftPointOld).equalTo(record::getGiftPointOld)
                 .set(giftPointNew).equalTo(record::getGiftPointNew)
                 .set(usePointLimitOld).equalTo(record::getUsePointLimitOld)
                 .set(usePointLimitNew).equalTo(record::getUsePointLimitNew)
                 .set(operateMan).equalTo(record::getOperateMan)
                 .set(createTime).equalTo(record::getCreateTime)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(PmsProductOperateLog record) {
        return update(c ->
                c.set(productId).equalToWhenPresent(record::getProductId)
                 .set(priceOld).equalToWhenPresent(record::getPriceOld)
                 .set(priceNew).equalToWhenPresent(record::getPriceNew)
                 .set(salePriceOld).equalToWhenPresent(record::getSalePriceOld)
                 .set(salePriceNew).equalToWhenPresent(record::getSalePriceNew)
                 .set(giftPointOld).equalToWhenPresent(record::getGiftPointOld)
                 .set(giftPointNew).equalToWhenPresent(record::getGiftPointNew)
                 .set(usePointLimitOld).equalToWhenPresent(record::getUsePointLimitOld)
                 .set(usePointLimitNew).equalToWhenPresent(record::getUsePointLimitNew)
                 .set(operateMan).equalToWhenPresent(record::getOperateMan)
                 .set(createTime).equalToWhenPresent(record::getCreateTime)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
